<template>
  <!-- 电控参数模板 -->
  <div class="water_control_parameters">
    <el-row>
      <dragdrop :width="0" :widthLeft="'150px'">
        <template slot="left">
          <div class="left_shuju">
            <div class="grid-content bg-purple">
              <div class="header_title">
                <span>模板数据</span>
              </div>
              <div class="addtemplate" v-if="isauth('water_p_edit')">
                <el-button
                  title="新增"
                  type="primary"
                  size="mini"
                  @click="addtForm"
                  icon="el-icon-plus"
                >新增模板</el-button>
              </div>
              <el-table
                :data="tableData"
                border
                @row-click="rowClick"
                highlight-current-row
                style="width: 100%"
                :header-cell-style="headFirst"
                :height="'calc(100vh - 220px)'"
              >
                <el-table-column align="center" prop="templateName" label="模板名称"></el-table-column>
                <el-table-column label="操作" align="center" v-if="isauth('water_p_edit')">
                  <template slot-scope="scope">
                    <el-button type="text" size="small" @click.stop="eidtDate(scope.row)">修改密码</el-button>
                    <el-button
                      type="text"
                      size="small"
                      v-if="userType === '1' || userType == '50' ? true : false"
                      @click.stop="resetDate(scope.row)"
                    >重置密码</el-button>
                    <el-button
                      type="text"
                      size="small"
                      style="color: red"
                      @click.stop="deleteDate(scope.row)"
                    >删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </template>
        <template slot="right">
          <div class="right_shuju">
            <div class="grid-content bg-purple-light" v-if="isShow">
              <el-tabs
                type="border-card"
                v-model="activeName"
                @tab-click="handleClick"
                v-loading="loading"
              >
                <el-tab-pane label="参数设置" name="first">
                  <div class="water_control_rules">
                    <el-form
                      :inline="true"
                      :model="elform"
                      class="demo-form-inline"
                      size="mini"
                      ref="elform"
                      :rules="elformRule"
                    >
                      <el-row>
                        <el-col :span="24">
                          <el-form-item label="设备操作密码:" prop="terminalOperationPassword">
                            <el-input
                              v-model="elform.terminalOperationPassword"
                              size="mini"
                              show-password
                              maxlength="4"
                              clearable
                              @keyup.native="
                                keyupEventInt($event, 'restrictionAmount')
                              "
                            ></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="9">
                          <el-form-item label="屏幕背光持续时间:" prop="backLightTime ">
                            <el-input-number
                              v-model="elform.backLightTime"
                              :min="0"
                              :max="255"
                              label
                              size="mini"
                              style="width: 100px"
                            ></el-input-number>
                            <span style=" marginleft: 5px">分钟，为0时常亮</span>
                          </el-form-item>
                        </el-col>
                        <el-col :span="7">
                          <el-form-item label="重复刷卡时间:" prop="repeatSwipeCardTime">
                            <el-input-number
                              v-model="elform.repeatSwipeCardTime"
                              :min="1"
                              :max="255"
                              label
                              size="mini"
                              style="width: 100px"
                            ></el-input-number>
                            <span style=" marginleft: 5px">秒</span>
                          </el-form-item>
                        </el-col>
                        <el-col :span="7">
                          <el-form-item label="刷卡间隔时间:" prop="creditCardSpaceTime">
                            <el-input-number
                              v-model="elform.creditCardSpaceTime"
                              :min="1"
                              :max="255"
                              label
                              size="mini"
                              style="width: 100px"
                            ></el-input-number>
                            <span style=" marginleft: 5px">* 0.1秒</span>
                          </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item label="是否检查名单" prop="rosterExamine">
                            <el-checkbox v-model="elform.rosterExamine"></el-checkbox>
                          </el-form-item>
                        </el-col>
                        <el-col :span="7" :offset="1">
                          <el-form-item label="名单类型:" prop="rosterType">
                            <el-select
                              v-model="elform.rosterType"
                              placeholder="请选择"
                              size="mini"
                              style="width: 100px"
                            >
                              <el-option
                                v-for="item in rosterTypeoption"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                              ></el-option>
                            </el-select>
                          </el-form-item>
                        </el-col>
                        <el-col :span="7">
                          <el-form-item label="名单分区字节序号:" prop="rosterDistrictByteOrder">
                            <el-select
                              v-model="elform.rosterDistrictByteOrder"
                              placeholder="请选择"
                              size="mini"
                              style="width: 80px"
                              disabled
                            >
                              <el-option
                                v-for="item in rosterDistrictByteOrderoption"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                              ></el-option>
                            </el-select>
                          </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item label="费率:" prop="hairDryerConsumptionRate">
                            <el-input-number
                              v-model="elform.hairDryerConsumptionRate"
                              :min="1"
                              :max="65535"
                              label
                              size="mini"
                              style="width: 120px"
                            ></el-input-number>
                            <span style=" marginleft: 5px">分钱/次</span>
                          </el-form-item>
                        </el-col>
                        <el-col :span="7" :offset="1">
                          <el-form-item label="每次使用时长:" prop="hairDryerEffectiveTime">
                            <el-input-number
                              v-model="elform.hairDryerEffectiveTime"
                              :min="1"
                              :max="65535"
                              label
                              size="mini"
                              style="width: 120px"
                            ></el-input-number>
                            <span style=" marginleft: 5px">秒/次</span>
                          </el-form-item>
                        </el-col>
                        <el-col :span="7">
                          <el-form-item label="是否检查卡内最大允许金额" prop="isCheckMaxAmount">
                            <el-checkbox v-model="elform.isCheckMaxAmount"></el-checkbox>
                          </el-form-item>
                        </el-col>
                        <el-col :span="5">
                          <el-form-item label="输出端口启用标志1" prop="outputPortEnableFlag1">
                            <el-checkbox v-model="elform.outputPortEnableFlag1"></el-checkbox>
                          </el-form-item>
                        </el-col>
                        <el-col :span="5">
                          <el-form-item label="输出端口启用标志2" prop="outputPortEnableFlag2">
                            <el-checkbox v-model="elform.outputPortEnableFlag2"></el-checkbox>
                          </el-form-item>
                        </el-col>
                        <el-col :span="5">
                          <el-form-item label="输出端口启用标志3" prop="outputPortEnableFlag3">
                            <el-checkbox v-model="elform.outputPortEnableFlag3"></el-checkbox>
                          </el-form-item>
                        </el-col>
                        <el-col :span="5">
                          <el-form-item label="输出端口启用标志4" prop="outputPortEnableFlag4">
                            <el-checkbox v-model="elform.outputPortEnableFlag4"></el-checkbox>
                          </el-form-item>
                        </el-col>

                        <!-- <el-col :span="7">
                          <el-form-item
                            label="输出端口启用标志:"
                            prop="hairDryerOutputPortEnableFlag"
                          >
                            <el-input-number
                              v-model="elform.hairDryerOutputPortEnableFlag"
                              :min="1"
                              :max="255"
                              label
                              size="mini"
                              style="width: 100px"
                            ></el-input-number>
                          </el-form-item>
                        </el-col>-->

                        <el-col :span="12">
                          <el-form-item label="卡内最大允许金额:" prop="cardMaxAmountMoney">
                            <el-col :span="14">
                              <el-input
                                v-model="elform.cardMaxAmountMoney"
                                size="mini"
                                clearable
                                @keyup.native="
                                  keyupEventInt($event, 'cardMaxAmountMoney')
                                "
                              ></el-input>
                            </el-col>

                            <el-col :span="10">
                              <span style=" marginleft: 5px">元，0则不限制</span>
                            </el-col>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">

                         <el-form-item label="无线模块重启计时:">
                            <el-input-number
                              v-model="elform.wirelessIdleRestartTiming"
                              :min="0"
                              :max="250"
                              label="0-250"
                            ></el-input-number>
                            <span style="color:red;marginLeft:5px">分 注:0标识不重启</span>
                          </el-form-item>
                        </el-col>
                        <!-- <el-col :span="8">
                          <el-form-item label="公共扇区" prop="commonSector">
                            <el-select
                              v-model="elform.commonSector"
                              placeholder="请选择"
                              size="mini"
                              style="width: 100px"
                            >
                              <el-option
                                :label="item - 1"
                                :value="item - 1"
                                v-for="item in 16"
                                :key="item.value"
                              ></el-option>
                            </el-select>
                          </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item
                            label="金额扇区"
                            prop="amountMoneySector"
                          >
                            <el-select
                              v-model="elform.amountMoneySector"
                              placeholder="请选择"
                              size="mini"
                              style="width: 100px"
                            >
                              <el-option
                                :label="item - 1"
                                :value="item - 1"
                                v-for="item in 16"
                                :key="item.value"
                              ></el-option>
                            </el-select>
                          </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item
                            label="脱机流水扇区"
                            prop="offLineFlowSector"
                          >
                            <el-select
                              v-model="elform.offLineFlowSector"
                              placeholder="请选择"
                              size="mini"
                              style="width: 100px"
                            >
                              <el-option
                                :label="item - 1"
                                :value="item - 1"
                                v-for="item in 16"
                                :key="item.value"
                              ></el-option>
                            </el-select>
                          </el-form-item>
                        </el-col>-->
                      </el-row>
                    </el-form>
                  </div>
                </el-tab-pane>
              </el-tabs>
              <div class="footer_card" v-if="isauth('hairdrider_p_edit')">
                <el-card class="box-card">
                  <div class="footerflex">
                    <div class="footer_save">
                      <el-input
                        size="mini"
                        v-model="alldatatemplatePassword"
                        show-password
                        placeholder="请输入密码"
                      ></el-input>
                    </div>
                    <div class="footer_save">
                      <el-button type="primary" size="mini" @click="savealldata">保存</el-button>
                    </div>
                    <div class="footer_save">
                      <!-- <el-button type="primary" size="mini" @click="onExport()">导出</el-button> -->
                    </div>
                    <!-- <div class="footer_parameter" style="padding: 0px 30px">
                      <span>把参数应用到...</span>
                      <el-select v-model="settlementunitGuid" placeholder="请选择" size="mini">
                        <el-option
                          v-for="item in settlementunitoption"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                      <el-button type="primary" size="mini" @click="applicationparameters">确定</el-button>
                    </div>-->
                    <div class="footer_merchant_equipment_parameters">
                      <el-button type="primary" size="mini" @click="savemerchant">重发参数模板</el-button>
                    </div>
                  </div>
                </el-card>
              </div>
            </div>
          </div>
        </template>
      </dragdrop>
    </el-row>
    <el-dialog
      :before-close="closeDialog"
      width="500px"
      center
      title="新增模板"
      :close-on-click-modal="false"
      :visible.sync="addDialogFormVisible"
    >
      <el-form :model="adddataForm" :rules="adddataRule" ref="adddataForm" label-width="80px">
        <el-form-item label="模板名称" prop="templateName">
          <el-col :span="15">
            <el-input v-model="adddataForm.templateName" placeholder="模板名称" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="模板密码" prop="templatePassword">
          <el-col :span="15">
            <el-input
              placeholder="请输入密码"
              v-model="adddataForm.templatePassword"
              show-password
              size="mini"
            ></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addvisible()">取消</el-button>
        <el-button type="primary" @click="addFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :before-close="eidtcloseDialog"
      width="500px"
      center
      title="修改模板"
      :close-on-click-modal="false"
      :visible.sync="eidtDialogFormVisible"
    >
      <el-form :model="eidtdataForm" :rules="adddataRule" ref="eidtdataForm" label-width="90px">
        <el-form-item label="模板名称" prop="templateName">
          <el-col :span="15">
            <el-input v-model="eidtdataForm.templateName" placeholder="模板名称" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="新模板密码" prop="newPassword">
          <el-col :span="15">
            <el-input
              placeholder="请输入新密码"
              v-model="eidtdataForm.newPassword"
              show-password
              :disabled="eidtdataForm.changepassword === false ? true : false"
              size="mini"
            ></el-input>
          </el-col>
          <el-col :span="5" style="paddingleft: 20px">
            <el-checkbox v-model="eidtdataForm.changepassword">是否修改密码</el-checkbox>
          </el-col>
        </el-form-item>
        <el-form-item label="原模板密码" prop="oldPassword">
          <el-col :span="15">
            <el-input
              placeholder="请输入密码,无则不填密"
              v-model="eidtdataForm.oldPassword"
              show-password
              size="mini"
            ></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="eidtvisible()">取消</el-button>
        <el-button type="primary" @click="eidtFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :before-close="resetcloseDialog"
      width="500px"
      center
      title="重置密码"
      :close-on-click-modal="false"
      :visible.sync="resetDialogFormVisible"
    >
      <el-form :model="resetdataForm" ref="resetdataForm" :rules="resetRule" label-width="110px">
        <el-form-item label="模板密码" prop="templatePassword">
          <el-col :span="15">
            <el-input
              placeholder="请输入密码"
              v-model="resetdataForm.templatePassword"
              show-password
              size="mini"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="确认模板密码" prop="confirmtemplatePassword">
          <el-col :span="15">
            <el-input
              placeholder="请输入新密码"
              v-model="resetdataForm.confirmtemplatePassword"
              show-password
              size="mini"
            ></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetvisible()">取消</el-button>
        <el-button type="primary" @click="resetFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { JSEncrypt } from 'jsencrypt'
export default {
  data() {
    let resetPassword = (rule, value, callback) => {
      if (this.resetdataForm.templatePassword !== value) {
        callback(new Error('确认密码与新密码不一致'))
      } else {
        callback()
      }
    }

    let cardMaxAmountMoneyRatecheck = (rule, value, callback) => {
      if (Number(value) >= 0 && Number(value) <= 65535) {
        callback()
      } else {
        callback(new Error('范围是0-65535'))
      }
    }
    return {
      isShow: false,
      leftS: 5,
      rightS: 19,
      isrightS: false,
      isletfS: true,
      //分组
      grouplistdata: [],
      loading: false,
      userType: '',
      temeplatecheck: false,
      publicKey:
        'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCx8wyZzYxaffWrJ4jooN554npe5vD2RSQGNXOY5UZz6hcIW0jdEk1KcdclE7mJPiI2DmgUjBp4Lau+bNmZxmLBqFHUMd29mWyqX+LuYVoymxs8f3VJF+7PqZzuKbtSOyXfcyjIIgtB06YlX4SXx4FCErGRx+MDseN2ObHSPme/3wIDAQAB',
      tableData: [],
      addDialogFormVisible: false,
      eidtDialogFormVisible: false,
      resetDialogFormVisible: false,
      adddataForm: {
        templateName: '',
        templatePassword: ''
      },
      eidtdataForm: {
        templateName: '',
        oldPassword: '',
        newPassword: '',
        templateGuid: '',
        changepassword: false
      },
      resetdataForm: {
        templatePassword: '',
        confirmtemplatePassword: '',
        templateGuid: ''
      },
      //重置密码规则
      resetRule: {
        templatePassword: [
          { required: true, message: '模板密码不能为空', trigger: 'blur' }
        ],
        confirmtemplatePassword: [
          { required: true, message: '确认模板密码不能为空', trigger: 'blur' },
          { validator: resetPassword, trigger: 'blur' }
        ]
      },
      adddataRule: {
        templateName: [
          { required: true, message: '模板名称不能为空', trigger: 'blur' }
        ]
      },
      activeName: 'first',

      rosterTypeoption: [
        {
          value: 1,
          label: '白名单'
        },
        {
          value: 0,
          label: '黑名单'
        }
      ],
      elform: {
        /**
         * 吹风机参数
         */
        backLightTime: 0,
        cardMaxAmountMoney: 0,
        creditCardSpaceTime: 0,
        hairDryerConsumptionRate: 0,
        hairDryerEffectiveTime: 0,
        hairDryerOutputPortEnableFlag: 0,
        isCheckMaxAmount: true,
        repeatSwipeCardTime: 0,
        rosterDistrictByteOrder: 0,
        rosterExamine: true,
        rosterType: 0,

        terminalOperationPassword: 0,
        // 无线模块重启计时
        wirelessIdleRestartTiming:0,

        //吹风机输出口1启用标识
        outputPortEnableFlag1: false,
        //吹风机输出口2启用标识
        outputPortEnableFlag2: false,
        //吹风机输出口3启用标识
        outputPortEnableFlag3: false,
        //吹风机输出口4启用标识
        outputPortEnableFlag4: false
      },
      // 名单分区字节序号
      rosterDistrictByteOrderoption: [
        {
          label: '0',
          value: 0
        },
        {
          label: '1',
          value: 1
        },
        {
          label: '2',
          value: 2
        },
        {
          label: '3',
          value: 3
        }
      ],
      //参数规则
      elformRule: {
        terminalOperationPassword: [
          { required: true, message: '请输入设备操作密码', trigger: 'blur' }
        ],
        cardMaxAmountMoney: [
          { validator: cardMaxAmountMoneyRatecheck, trigger: 'blur' }
        ]
      },

      searchInfo: {},
      //下发参数
      settlementunitGuid: '',
      settlementunitoption: [],
      //保存密码
      alldatatemplatePassword: '',
      //模板id
      templateGuid: ''
    }
  },
  created() {
    this.operatorGuid = sessionStorage.getItem('administrator')
    this.userType = sessionStorage.getItem('userType')
  },
  mounted() {
    this.getmodelselect()
    this.unitmerchantpage()
    this.grouplist()
  },
  filters: {
    filtergroupCode: function(groupCode, grouplistdata) {
      for (var j = 0; j < grouplistdata.length; j++) {
        if (groupCode == grouplistdata[j].value) {
          groupCode = grouplistdata[j].label
        }
      }
      return groupCode
    }
  },
  computed: {
    changeschoolid: {
      get() {
        return this.$store.state.user.changeschoolid
      }
    }
  },
  methods: {
    keyupEvent(e, name) {
      e.target.value = e.target.value.replace(/[^\d.]/g, '')
      e.target.value = e.target.value.replace(/\.{2,}/g, '.')
      e.target.value = e.target.value.replace(/^\./g, '0.')
      e.target.value = e.target.value.replace(
        /^\d*\.\d*\./g,
        e.target.value.substring(0, e.target.value.length - 1)
      )

      e.target.value = e.target.value.replace(/^0[^\.]+/g, '0')
      e.target.value = e.target.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2')
      this.elform[name] = e.target.value
    },
    keyupEventInt(e, name) {
      e.target.value = e.target.value.replace(/[^\d]/g, '')
      this.elform[name] = e.target.value
    },
    leftSClick() {
      this.isrightS = true
      this.leftS = 0
      this.rightS = 24
      this.isletfS = false
    },
    rightSClick() {
      this.isrightS = false
      this.leftS = 5
      this.rightS = 19
      this.isletfS = true
    },
    // 分组查询
    grouplist() {
      this.grouplistdata = []
      this.$http({
        url: this.$http.adornUrl('/unit/unit-user-group-list'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: this.changeschoolid,
          messageType: this.messageType
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          for (var i = 0; i < data.messageContent.length; i++) {
            let itemobj = {
              label: data.messageContent[i].groupName,
              value: data.messageContent[i].groupCode
            }
            this.grouplistdata.push(itemobj)
          }
        } else {
          this.$message({
            showClose: true,
            message: data.errorMessage,
            type: 'error'
          })
        }
      })
    },
    //结算单位
    unitmerchantpage() {
      this.settlementunitoption = []
      this.searchInfo.unitGuid = this.changeschoolid
      this.$http({
        url: this.$http.adornUrl('/terminal/merchant/unit-merchant-page'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            pageNum: 1,
            pageSize: 999999,
            searchInfo: this.searchInfo
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          console.log(data)
          for (var i = 0; i < data.messageContent.data.length; i++) {
            let itemobj = {
              label: data.messageContent.data[i].merchantName,
              value: data.messageContent.data[i].merchantGuid
            }
            this.settlementunitoption.push(itemobj)
          }
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    // 删除模板
    deleteDate(row) {
      this.$prompt('请输入密码,无则不输入', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
        .then(({ value }) => {
          if (value !== null && value !== '') {
            let templatePassword = value
            let encryptor = new JSEncrypt()
            encryptor.setPublicKey(this.publicKey)
            templatePassword = encryptor.encrypt(this.$md5(templatePassword))
            this.delwaterparamete(row.templateGuid, templatePassword)
          } else {
            let templatePassword = ''
            this.delwaterparamete(row.templateGuid, templatePassword)
          }
        })
        .catch(() => {})
    },
    resetDate(row) {
      this.resetdataForm.templateGuid = row.templateGuid
      this.resetDialogFormVisible = true
    },
    resetvisible() {
      this.resetDialogFormVisible = false
      this.$refs['resetdataForm'].resetFields()
    },
    resetcloseDialog(done) {
      this.$refs['resetdataForm'].resetFields()
      done()
    },
    eidtDate(row) {
      this.eidtdataForm.changepassword = false
      this.eidtdataForm.templateName = row.templateName
      this.eidtdataForm.templateGuid = row.templateGuid
      this.eidtDialogFormVisible = true
    },
    eidtvisible() {
      this.eidtDialogFormVisible = false
      this.$refs['eidtdataForm'].resetFields()
    },
    eidtcloseDialog(done) {
      this.$refs['eidtdataForm'].resetFields()
      done()
    },

    addtForm() {
      this.addDialogFormVisible = true
    },
    closeDialog(done) {
      this.$refs['adddataForm'].resetFields()
      done()
    },
    addvisible() {
      this.addDialogFormVisible = false
      this.$refs['adddataForm'].resetFields()
    },
    addFormSubmit() {
      this.$refs['adddataForm'].validate(valid => {
        if (valid) {
          if (
            this.adddataForm.templatePassword !== null &&
            this.adddataForm.templatePassword !== ''
          ) {
            let encryptor = new JSEncrypt()
            encryptor.setPublicKey(this.publicKey)
            let templatePassword = encryptor.encrypt(
              this.$md5(this.adddataForm.templatePassword)
            )
            this.addwaterparameter(
              this.adddataForm.templateName,
              templatePassword
            )
          } else {
            let templatePassword = ''
            this.addwaterparameter(
              this.adddataForm.templateName,
              templatePassword
            )
          }
        }
      })
    },
    //新增电吹风模板接口
    addwaterparameter(templateName, templatePassword) {
      this.$http({
        url: this.$http.adornUrl('/terminal/hair/hair-parameter-add'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            templateName: templateName,
            templatePassword: templatePassword,
            unitGuid: this.changeschoolid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.$message({
            message: '新增模板成功',
            type: 'success'
          })
          this.$refs['adddataForm'].resetFields()
          this.addDialogFormVisible = false
          this.getmodelselect()
        } else {
          this.$message({
            message: data.errorMessage,
            type: 'error'
          })
        }
      })
    },
    //删除电吹风模板接口
    delwaterparamete(templateGuid, templatePassword) {
      this.$http({
        url: this.$http.adornUrl('/terminal/hair/hair-parameter-delete'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            templateGuid: templateGuid,
            templatePassword: templatePassword,
            unitGuid: this.changeschoolid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.$message({
            message: '删除模板成功',
            type: 'success'
          })
          this.getmodelselect()
        } else {
          this.$message({
            message: data.errorMessage,
            type: 'error'
          })
        }
      })
    },
    //修改电吹风密码
    eidtFormSubmit() {
      this.$refs['eidtdataForm'].validate(valid => {
        if (valid) {
          if (
            this.eidtdataForm.oldPassword === '' ||
            this.eidtdataForm.oldPassword === null
          ) {
            var oldPassword = ''
          }
          if (
            this.eidtdataForm.newPassword === '' ||
            this.eidtdataForm.newPassword === null
          ) {
            var newPassword = ''
          }
          if (
            this.eidtdataForm.oldPassword !== '' &&
            this.eidtdataForm.oldPassword !== null
          ) {
            let encryptor = new JSEncrypt()
            encryptor.setPublicKey(this.publicKey)
            var oldPassword = encryptor.encrypt(
              this.$md5(this.eidtdataForm.oldPassword)
            )
          }
          if (
            this.eidtdataForm.newPassword !== '' &&
            this.eidtdataForm.newPassword !== null
          ) {
            let encryptor = new JSEncrypt()
            encryptor.setPublicKey(this.publicKey)
            var newPassword = encryptor.encrypt(
              this.$md5(this.eidtdataForm.newPassword)
            )
          }
          if (this.eidtdataForm.changepassword == false) {
            var newPassword = null
          }
          this.$http({
            url: this.$http.adornUrl('/terminal/template-update-password'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                newPassword: newPassword,
                oldPassword: oldPassword,
                unitGuid: this.changeschoolid,
                templateName: this.eidtdataForm.templateName,
                templateGuid: this.eidtdataForm.templateGuid,
                terminalType: 28
              },
              messageType: this.messageType
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                showClose: true,
                message: '修改成功',
                type: 'success'
              })
              this.getmodelselect()
              this.eidtDialogFormVisible = false
              this.$refs['eidtdataForm'].resetFields()
            } else {
              this.$message({
                showClose: true,
                message: data.errorMessage,
                type: 'error'
              })
            }
          })
        }
      })
    },
    //重置电吹风密码
    resetFormSubmit() {
      this.$refs['resetdataForm'].validate(valid => {
        if (valid) {
          let encryptor = new JSEncrypt()
          encryptor.setPublicKey(this.publicKey)
          var confirmtemplatePassword = encryptor.encrypt(
            this.$md5(this.resetdataForm.confirmtemplatePassword)
          )
          this.$http({
            url: this.$http.adornUrl('/terminal/template-reset-password'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                templatePassword: confirmtemplatePassword,
                templateGuid: this.resetdataForm.templateGuid,
                unitGuid: this.changeschoolid,
                operatorGuid: this.operatorGuid
              },
              messageType: this.messageType
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                showClose: true,
                message: '重置成功',
                type: 'success'
              })
              this.getmodelselect()
              this.resetDialogFormVisible = false
              this.$refs['resetdataForm'].resetFields()
            } else {
              this.$message({
                showClose: true,
                message: data.errorMessage,
                type: 'error'
              })
            }
          })
        }
      })
    },
    handleClick() {},
    //获取房间模板参数列
    getmodelselect() {
      this.$http({
        url: this.$http.adornUrl('/terminal/template-model-select'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            terminalType: 28,
            unitGuid: this.changeschoolid
          },
          messageType: this.messageType
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          console.log(data)
          this.tableData = data.messageContent
        } else {
          this.$message({
            showClose: true,
            message: data.errorMessage,
            type: 'error'
          })
        }
      })
    },
    //表格点击事件
    rowClick(row) {
      // 显示模板信息
      this.isShow = true
      this.temeplatecheck = true
      console.log(row)
      this.templateGuid = row.templateGuid
      this.waterparametersearch(row.templateGuid)
    },
    //查询电吹风
    waterparametersearch(templateGuid) {
      this.loading = true
      this.$http({
        url: this.$http.adornUrl('/terminal/hair/hair-parameter-search'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            templateGuid: templateGuid,
            unitGuid: this.changeschoolid
          },
          messageType: this.messageType
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.alldata = data.messageContent
          this.elform.backLightTime = this.alldata.backLightTime
          this.elform.cardMaxAmountMoney = this.alldata.cardMaxAmountMoney
          this.elform.wirelessIdleRestartTiming = this.alldata.wirelessIdleRestartTiming
          
          this.elform.creditCardSpaceTime = this.alldata.creditCardSpaceTime
          this.elform.hairDryerConsumptionRate = this.alldata.hairDryerConsumptionRate
          this.elform.hairDryerEffectiveTime = this.alldata.hairDryerEffectiveTime
          this.elform.hairDryerOutputPortEnableFlag = this.alldata.hairDryerOutputPortEnableFlag
          this.elform.isCheckMaxAmount = this.alldata.isCheckMaxAmount
          this.elform.repeatSwipeCardTime = this.alldata.repeatSwipeCardTime
          this.elform.rosterDistrictByteOrder = this.alldata.rosterDistrictByteOrder
          this.elform.rosterExamine = this.alldata.rosterExamine
          this.elform.rosterType = this.alldata.rosterType
          this.elform.terminalOperationPassword = this.alldata.terminalOperationPassword
          /**输出端口 */
          this.elform.outputPortEnableFlag1 = this.alldata.outputPortEnableFlag1
          this.elform.outputPortEnableFlag2 = this.alldata.outputPortEnableFlag2
          this.elform.outputPortEnableFlag3 = this.alldata.outputPortEnableFlag3
          this.elform.outputPortEnableFlag4 = this.alldata.outputPortEnableFlag4

          this.loading = false
        } else {
          this.$message({
            showClose: true,
            message: data.errorMessage,
            type: 'error'
          })
        }
      })
    },
    //保存修改参数
    savealldata() {
      if (this.temeplatecheck === false) {
        this.$message({
          message: '请选择模板保存',
          type: 'warning'
        })
        return
      }
      this.$refs['elform'].validate(valid => {
        if (valid) {
          if (
            this.alldatatemplatePassword !== null &&
            this.alldatatemplatePassword !== ''
          ) {
            let encryptor = new JSEncrypt()
            encryptor.setPublicKey(this.publicKey)
            var templatePassword = encryptor.encrypt(
              this.$md5(this.alldatatemplatePassword)
            )
          } else {
            var templatePassword = null
          }
          this.$http({
            url: this.$http.adornUrl('/terminal/hair/hair-parameter-update'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                parameterData: this.elform,
                templateGuid: this.templateGuid,
                templatePassword: templatePassword,
                unitGuid: this.changeschoolid
              },
              messageType: this.messageType
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                message: '修改模板成功',
                type: 'success'
              })
              this.waterparametersearch(this.templateGuid)
              this.alldatatemplatePassword = ''
            } else {
              this.$message({
                showClose: true,
                message: data.errorMessage,
                type: 'error'
              })
              // this.waterparametersearch(this.templateGuid);
            }
          })
        }
      })
    },
    //导出参数
    onExport() {},
    //下发参数
    applicationparameters() {
      if (this.settlementunitGuid == null || this.settlementunitGuid == '') {
        this.$message({
          type: 'warning',
          message: '请选择应用商户!'
        })
        return
      }
      if (this.templateGuid == null || this.templateGuid == '') {
        this.$message({
          type: 'warning',
          message: '请选择参数模板!'
        })
        return
      }
      this.$http({
        url: this.$http.adornUrl(
          '/terminal/consume/consume-parameter-build-merchant'
        ),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            merchantGuid: this.settlementunitGuid,
            templateGuid: this.templateGuid,
            unitGuid: this.changeschoolid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.$message({
            type: 'success',
            message: '应用成功!'
          })
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    //重发参数
    savemerchant() {
      if (this.templateGuid == null || this.templateGuid == '') {
        this.$message({
          type: 'warning',
          message: '请选择参数模板!'
        })
        return
      }
      this.$confirm('是否重发该模板的参数?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl('/terminal/reset-template'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                // merchantGuid: this.settlementunitGuid,
                templateGuid: this.templateGuid,
                unitGuid: this.changeschoolid
              },
              messageType: 0
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                type: 'success',
                message: '下发成功!'
              })
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.water_control_parameters {
  /deep/.el-table {
    /deep/tbody tr:hover > td {
      cursor: pointer;
    }
  }
  // padding: 20px;
  .right_shuju {
    .water_control_rules {
      .md_fq_content /deep/ .el-form-item__content {
        width: 46%;
      }
      .max_ks_cs /deep/ .el-form-item__content {
        width: 500px;
      }
      .lx_kf_sb /deep/ .el-form-item__content {
        width: 55%;
      }
    }
  }
  //滚动条的宽度
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  //滚动条的滑块
  ::-webkit-scrollbar-thumb {
    background-color: #a1a3a9;
    border-radius: 3px;
  }
  .grid-content {
    min-height: 600px;
    .header_title,
    .addtemplate {
      padding: 20px 0;
      font-weight: bolder;
      padding-left: 20px;
      border-bottom: 1px solid #e5e9f2;
      color: #909399;
      overflow: hidden;
      text-align: center;
    }
  }
  .bg-purple {
    height: 100%;
    height: auto;
  }
  .bg-purple-light {
    padding: 20px 0px;
    .footer_card {
      height: 110px;
      display: flex;
      align-items: center;
      .el-card.is-always-shadow,
      .el-card.is-hover-shadow:focus,
      .el-card.is-hover-shadow:hover {
        width: 100%;
        height: 60%;
      }
    }
    .footer_card /deep/ .el-card__body {
      height: 100% !important;
      padding: 0px 20px;
      .footerflex {
        height: 100%;
        display: flex;
        align-items: center;
        display: -webkit-flex;
        justify-content: space-between;
      }
    }
  }
}
</style>
